package mapeditor.mappanel.old;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JLabel;

public class ImageLabelMapView extends JLabel
{
	public ImageIcon		testimg		= getImage( false );
	public ImageIcon		testimg2	= getImage( true );
	public static ImageIcon	test		= getImageStatic( false );

	public ImageLabelMapView() {
		super( );
		setIcon( testimg );
		setPreferredSize( new Dimension( 25 , 25 ) );
		addMouseListener( new IconMotionListener( this ) );
	}

	private static ImageIcon getImageStatic( boolean b )
	{
		ImageIcon icon = null;
		try {
			BufferedImage bi = ImageIO.read( new File( "lol.gif" ) );
			if ( b ) {
				for ( int i = 0 ; i < bi.getHeight( ) ; i++ ) {
					for ( int j = 0 ; j < bi.getWidth( ) ; j++ ) {
						Color c = new Color( bi.getRGB( j , i ) );
						Color cc = new Color(

						(c.getRed( ) - 50) < 0 ? 0 : (c.getRed( ) - 50) ,

						(c.getRed( ) - 50) < 0 ? 0 : (c.getRed( ) - 50) ,

						(c.getRed( ) - 50) < 0 ? 0 : (c.getRed( ) - 50) );

						bi.setRGB( j , i , cc.getRGB( ) );
					}
				}
			}

			icon = new ImageIcon( bi.getScaledInstance( 50 , 50 ,
					Image.SCALE_FAST ) );
		} catch ( IOException e ) {
			// TODO Auto-generated catch block
			e.printStackTrace( );
		}
		return icon;
	}

	private ImageIcon getImage( boolean b )
	{
		ImageIcon icon = null;
		try {
			BufferedImage bi = ImageIO.read( new File( "lol.gif" ) );
			if ( b ) {
				for ( int i = 0 ; i < bi.getHeight( ) ; i++ ) {
					for ( int j = 0 ; j < bi.getWidth( ) ; j++ ) {
						Color c = new Color( bi.getRGB( j , i ) );
						Color cc = new Color(

						(c.getRed( ) - 50) < 0 ? 0 : (c.getRed( ) - 50) ,

						(c.getRed( ) - 50) < 0 ? 0 : (c.getRed( ) - 50) ,

						(c.getRed( ) - 50) < 0 ? 0 : (c.getRed( ) - 50) );

						bi.setRGB( j , i , cc.getRGB( ) );
					}
				}
			}

			icon = new ImageIcon( bi.getScaledInstance( 25 , 25 ,
					Image.SCALE_FAST ) );
		} catch ( IOException e ) {
			// TODO Auto-generated catch block
			e.printStackTrace( );
		}
		return icon;
	}

}
